package com.study.rabbit.producer;

import org.junit.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @description BroadcastProducerTest 广播测试
 * @author TDW
 * @date 2018年10月30日
 *
 */
public class BroadcastProducerTest {
	private static RabbitTemplate rabbitTemplate;
	static{
			ApplicationContext ac = new ClassPathXmlApplicationContext("MQContext.xml");
			rabbitTemplate = (RabbitTemplate) ac.getBean("amqpTemplate");
	}
	
	@Test
	public void testAll() {
		String opType = "2000";
		String msg = "abcd收到消息后你们各自刷新你们的服务器配置文件";
		System.out.println("op_type="+opType+",msg="+msg);
		MessageProperties properties = new MessageProperties();
		properties.setHeader("op_type", opType);
		Message message = new Message(msg.getBytes(),properties);
		try{
			rabbitTemplate.send("broadcastABCDExchange","*",message);
			System.out.println("消息发送成功");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			System.exit(0);//退出
		}
	}
	
	@Test
	public void testPart() {
		String opType = "2000";
		String msg = "abcd收到消息后你们各自刷新你们的服务器配置文件";
		System.out.println("op_type="+opType+",msg="+msg);
		MessageProperties properties = new MessageProperties();
		properties.setHeader("op_type", opType);
		Message message = new Message(msg.getBytes(),properties);
		try{
			rabbitTemplate.send("testBroadcastABCDExchange","test",message);
			System.out.println("消息发送成功");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			System.exit(0);//退出
		}
	}
	
}
